package com.jyhg.ane.component.dialog
{
	import com.distriqt.extension.dialog.Dialog;
	import com.distriqt.extension.dialog.events.DialogEvent;
	import com.jyhg.core.mobile.ANEdistriqt;
	import com.jyhg.core.mobile.base.JSprite;
	
	import flash.utils.setInterval;
	
	
	/**
	 * JANEDialog
	 * @author: Jonny.Hong
	 * @date: 2014-2-26
	 */
	public class JANEDialog extends JSprite
	{
		protected var _id:int;
		public function JANEDialog()
		{
			super();
			init();
		}
		
		override public function init():void
		{
			try
			{
				Dialog.init( ANEdistriqt.DEV_KEY );
				Dialog.service.addEventListener( DialogEvent.DIALOG_CLOSED, dialog_dialogClosedHandler, false, 0, true );
				Dialog.service.addEventListener( DialogEvent.DIALOG_CANCELLED, dialog_dialogCancelledHandler, false, 0, true );
			}
			catch (e:Error)
			{
				trace( "ERROR::"+e.message );
			}
		}
		
		public function set closeTime(value:int):void
		{
			setInterval(close,value);
		}
		
		protected function dialog_dialogCancelledHandler(event:DialogEvent):void
		{
			trace("cancel index:" , event.data);
		}
		
		protected function dialog_dialogClosedHandler(event:DialogEvent):void
		{
			trace("closed index" , event.data);
		}
		
		public function close():void
		{
			Dialog.service.dismissDialog(_id);
			Dialog.service.removeEventListener( DialogEvent.DIALOG_CLOSED, dialog_dialogClosedHandler);
			Dialog.service.removeEventListener( DialogEvent.DIALOG_CANCELLED, dialog_dialogCancelledHandler);
		}
	}
}